const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // id:101495,
    id:68978,
    detail:[],
    IsQJD:0,
    IsSC:0,
    IsShowSCBtn:0,
    Jyfl:'',
    ComInfo:'',
    Other:[],
    Zhengshu:[],
    CallTel:false,
    IsShowPL:0,
    Tel:'',
    // pinglun:false,
    pinglun:false,
    star:['icon-shoucangdianjihou','icon-shoucangdianjihou','icon-shoucangdianjihou','icon-shoucangdianjihou','icon-shoucangdianjihou'],
    Fs:[],
    fstishi:'',
    fenshu:5,
    Key:[],
    keyarr:[],
    fsidx:4,
    textFoucus:0,
    content:'',

  },
  textFoucus:function () {
    this.setData({
      textFoucus:500
    })
  },
  textBlur:function () {
    this.setData({
      textFoucus:0
    })
  },
  guanbi:function () {
    this.setData({
      pinglun:false
    })
  },
  textarea:function (e) {
    this.setData({
      content:e.detail.value
    })
  },
  tijiao:function () {
    // LoginUID:登录人id，PType:：1回收信息详情页 2回收企业主页 3资产详情页，InfoID:信息编号，FS:分数，Key:关键词逗号隔开，content:评论内容
    if (app.checkFjLogin()) {
      var FjLoginLog = wx.getStorageSync('FjLoginLog'); 
      var KeyStr = '';
      for (var i = 0; i < this.data.keyarr.length; i++) {
        if (this.data.keyarr[i].sel == 1) {
          KeyStr = KeyStr + this.data.keyarr[i].name + ',';
        }
      }
      KeyStr = (KeyStr.substring(KeyStr.length - 1) == ',') ? KeyStr.substring(0, KeyStr.length - 1) : KeyStr;
      var api_input = {
        LoginUID:FjLoginLog.UID,
        PType:1,
        InfoID:this.data.id,
        FS:this.data.fenshu,
        Key:KeyStr,
        content:this.data.content
      }
      var that = this;
      app.getDaoPostN('api/FJDispose/FJ_Add_PingLun',api_input,r=>{
        
        if (r.code==200) {
          that.setData({
            pinglun:false
          })
          app.tishi(r.data)
        }else{
          app.tishi(r.data)
        }
      })   
    }else{
      wx.navigateTo({ url: '../../pages/login/index' }); 
    }   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  starNum:function (e) {
    this.setData({
      star:['icon-shoucangdianjihou','icon-shoucangdianjihou','icon-shoucangdianjihou','icon-shoucangdianjihou','icon-shoucangdianjihou'],
    })
    var num = e.currentTarget.dataset.idx;
    for (var i = num+1; i < 5; i++) {
      var stararr = 'star['+i+']';
      this.setData({
        [stararr]:'icon-star'
      })
    }
    // console.log(this.data.Key);return false;
    var keyselarr = new Array;
  
    var keysel = this.data.Key[num].split(",");
    for (var i = 0; i < keysel.length; i++) {
      var arr = {
        name:keysel[i],
        sel:0
      }
      keyselarr[i] = arr;
    }
    this.setData({
      fstishi:this.data.Fs[num],
      fenshu:num+1,
      keyarr:keyselarr
    })
  
  },
  selectKey:function (e) {
    var keyarr = this.data.keyarr;
    if (keyarr[e.currentTarget.dataset.idx].sel == 0) {
      keyarr[e.currentTarget.dataset.idx].sel = 1;
    }else{
      keyarr[e.currentTarget.dataset.idx].sel = 0;
    }
    this.setData({
      keyarr:keyarr
    })
  },
  onLoad: function (options) {
    
    
    this.setData({
      id:options.id
    })
    var PingLunXing = wx.getStorageSync('PingLunXing');
    if (PingLunXing.fstishi) {
      this.setData({
        Fs:PingLunXing.Fs,
        Key:PingLunXing.Key,
        fstishi:PingLunXing.fstishi,
        keyarr:PingLunXing.keyarr        
      })
    }else{
      this.getPlXing();
    }
    this.getFJ_Get_RecTypeInfo();
  },

  toCall:function () {
    if (app.checkFjLogin()) {
      var FjLoginLog = wx.getStorageSync('FjLoginLog'); 
      var api_input = {
        UID:FjLoginLog.UID,
        VType:1,
        InfoID:this.data.id
      }
      var that = this;
      app.getDaoPostN('api/FJDispose/FJ_Add_RecLinkInfo',api_input,r=>{
        if (r.code==200) {
          that.setData({
            Tel:r.data.Tel,
            IsShowPL:r.data.IsShowPL,
            CallTel:true
          })
        }
      })   
    }else{
      wx.navigateTo({ url: '../../pages/login/index' }); 
    }
  },
  toCallTel:function () {
    var that = this;
    wx.makePhoneCall({
      phoneNumber: that.data.Tel,  // 必填，需要拨打的电话号码
      success: (res) => {
          if (that.data.IsShowPL == 1) {
            that.setData({
              pinglun:true,
            }) 
          }
          that.setData({
            CallTel:false,
          })
      },
      fail: (res) => {
        that.setData({
          CallTel:false
        })
      }      
    })

  },
  chickTelZheZhao:function () {
    this.setData({
      CallTel:false
    })
  },
  chickPlZheZhao:function () {
    this.setData({
      pinglun:false
    })    
  },
  zhuzhimaopao:function () {
    // body...
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getFJ_Get_RecTypeInfo:function () {
    var that = this;
    var api_input = {id:this.data.id}  
    app.getDaoPost('api/FJDispose/FJ_Get_RecTypeInfo', api_input,r =>{
        if (r.code == 200) {
          var imgs = r.data.Info[0].Photo.split('|');
          r.data.Info[0].Photo = imgs[0];

          var oother = r.data.Other;
          for (var i = 0; i < oother.length; i++) {
            var ooimg = oother[i].Photo.split('|');
            oother[i].Photo = ooimg[0]
          }
          // console.log(imgs)
          that.setData({
            detail:r.data.Info[0],
            IsQJD:r.data.IsQJD,
            IsSC:r.data.IsSC,
            IsShowSCBtn:r.data.IsShowSCBtn,
            Jyfl:r.data.Jyfl.trim(),
            ComInfo:r.data.ComInfo,
            Other:oother,
            Zhengshu:r.data.Zhengshu       
          })
        }else{
          app.tishi(r.message)
        }

    })
  }, 
  getPlXing:function () {
    var that = this;
    app.getDaoPost('api/FJDispose/FJ_Get_PingLun','{}',function (r) {
      var word = that.data.Fs;
      word.push(r.data.FS.One);
      word.push(r.data.FS.Two);
      word.push(r.data.FS.Three);
      word.push(r.data.FS.Four);
      word.push(r.data.FS.Five);
      var keyword = that.data.Key;
      keyword.push(r.data.Key.One);
      keyword.push(r.data.Key.Two);
      keyword.push(r.data.Key.Three);
      keyword.push(r.data.Key.Four);
      keyword.push(r.data.Key.Five);
      var five = r.data.Key.Five.split(",");
      var keyarr = new Array;
      for (var i = 0; i < five.length; i++) {
        var arr = {
          name:five[i],
          sel:0
        }
        keyarr[i] = arr;        
      }
      var apo = {
        Fs:word,
        Key:keyword,
        fstishi:r.data.FS.Five,
        keyarr:keyarr        
      }
      wx.setStorageSync('PingLunXing',apo);
      that.setData(apo);           
    })
  },
  toruzhu:function () {
    if (app.checkFjLogin()) {
      wx.navigateTo({ url: '../user/mywyczsp' }); 
    }else{
      wx.navigateTo({ url: '../../pages/login/index' }); 
    } 
  }

})